#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

class student
{
private:
    string ID, name;
    vector<string> courses;
    vector<double> score;
    double ave;

public:
    student(){};
    void _set_ID(string str)
    {
        ID = str;
    }

    void _set_name(string str)
    {
        name = str;
    }

    void _set_courses(string str, double s)
    {
        courses.push_back(str);
        score.push_back(s);
    }

    string _ID()
    {
        return ID;
    }

    string _name()
    {
        return name;
    }

    double _score(string str)
    {
        for (int i = 0; i < courses.size(); i++)
        {
            if (courses[i] == str)
                return score[i];
        }
        return -1;
    }

    void _output(vector<string> str)
    {
        cout << ID << ", " << name << ", ";
        double sum = 0;
        int n = 0;
        for (int i = 0; i < str.size(); i++)
        {
            int cnt = 0; // have the course or not

            for (int j = 0; j < courses.size(); j++)
            {
                if (str[i] == courses[j])
                {
                    cout << fixed << setprecision(1) << score[j] << ", ";
                    cnt++;
                    sum = sum + score[j];
                    n++;
                }
            }

            if (cnt == 0)
            {
                cout << ", ";
            }
        }
        ave = sum / n;
        cout << fixed << setprecision(1) << ave << endl;
    }
};

class format
{
private:
    vector<string> courses_list, ID_list;
    vector<student> s;
    double score;

public:
    format(){};
    bool is_name(string str)
    {
        int num = 0;
        for (int i = 0; i < str.length(); i++)
        {
            if (str[i] == ',')
                num++;
        }
        if (num == 1)
            return true;
        else
            return false;
    }

    int findPosVector(vector<string> input, string str)
    {
        vector<string>::iterator iter = find(input.begin(), input.end(), str);
        if (iter == input.end())
        {
            return -1;
        }
        else
        {
            return distance(input.begin(), iter);
        }
    }

    void set_stu(string str)
    {
        if (is_name(str))
        {
            string s1, s2;
            s1 = str.substr(0, 10);
            s2 = str.substr(12);
            if (findPosVector(ID_list, s1) == -1) // not found, new student
            {
                ID_list.push_back(s1);
                student p;
                p._set_ID(s1);
                p._set_name(s2);
                s.push_back(p);
            }
            else // found
            {
                int no = findPosVector(ID_list, s1);
                s[no]._set_name(s2);
            }
        }
        else // not name but info of courses
        {
            string s1, s2;
            double s0;
            s1 = str.substr(0, 10);                       // ID
            s2 = str.substr(12, str.find(',', 11) - 12);  // course name
            s0 = stod(str.substr(str.find(',', 11) + 2)); // score
            if (findPosVector(ID_list, s1) == -1)         // not found, new student
            {
                ID_list.push_back(s1);
                if (findPosVector(courses_list, s2) == -1) // new course
                {
                    courses_list.push_back(s2);
                }
                student p;
                p._set_ID(s1);
                p._set_courses(s2, s0);
                s.push_back(p);
            }
            else // found student
            {
                int no = findPosVector(ID_list, s1);
                s[no]._set_courses(s2, s0);
                if (findPosVector(courses_list, s2) == -1) // new course
                {
                    courses_list.push_back(s2);
                }
            }
        }
    }

    void output()
    {
        // print fist line
        sort(courses_list.begin(), courses_list.end());
        cout << "student id, name, ";
        for (int i = 0; i < courses_list.size(); i++)
        {
            cout << courses_list[i] << ", ";
        }
        cout << "average" << endl;

        // print table
        sort(ID_list.begin(), ID_list.end());
        for (int i = 0; i < ID_list.size(); i++)
        {
            for (int j = 0; j < s.size(); j++)
            {
                if (ID_list[i] == s[j]._ID())
                {
                    s[j]._output(courses_list);
                }
            }
        }
        // print total average
        cout << ", "
             << ", ";
        double Sum = 0; // sum of average
        for (int i = 0; i < courses_list.size(); i++)
        {
            double sum = 0;
            int cnt = 0;
            for (int j = 0; j < s.size(); j++)
            {
                if (s[j]._score(courses_list[i]) != -1)
                {
                    sum = s[j]._score(courses_list[i]) + sum;
                    cnt++;
                }
            }
            cout << fixed << setprecision(1) << sum / cnt << ", ";
            Sum = Sum + sum / cnt;
        }
        if (courses_list.size() == 0)exit(0);
        if (courses_list.size() == 0)
            cout << endl;
        else
            cout << fixed << setprecision(1) << Sum / courses_list.size() << endl;
    }
};

int main()
{
    format f;
    string str;
    while (getline(cin, str))
    {
        if (str.empty())
            break;
        f.set_stu(str);
    }
    f.output();
    return 0;
}